<template>
	<view>
		<view class="order_list">
			<view class="b-header">
				<pageHeader title="订单"></pageHeader>
				<tab :datas="tab" @tabClick="tabClick" :selected="status"></tab>
			</view>
			
			<view :style="{height: 35+statusBarHeight+toBarHeight+'px'}"></view> 
			<!-- 占位 -->
			<view class="table_income ">
				<view class="head mui-row  ">
					<view class="mui-col-xs-3 item-name text-center">订单项目</view> 
					<view class="mui-col-xs-3 item-name">购买者</view> 
					<view class="mui-col-xs-3 item-name">销售代理</view> 
					<view class="mui-col-xs-3 item-name fz10">利润/售价</view>
				</view>
				<div class="body">
					<div class="item mui-row mui-text-center">
						<div class="mui-col-xs-3 goods">
							<div><img src="http://lanlanli.lemangweb.com/upload/editor/image/20201216/3333-1608106168.jpg"> <div>测试2</div></div>
							</div> 
						<div class="mui-col-xs-3 qlogo"><img src="http://lanlanli.lemangweb.com/home/img/user.jpg?015"> 
						<div style="height: 16px; overflow: hidden;">tietie</div> 
						<div class="text-gray font-size-xs">ID:LL010293</div> <span class="mui-badge mui-badge-black font-size-xs"></span></div> 
						<div class="mui-col-xs-3 qlogo"><img src="http://thirdwx.qlogo.cn/mmopen/574VdhMFwaF13R2FvQAvibtaicVq7bHDAlfH37QVenAAoIE1CtjM1KoJKDk9sVAKMjnFUssk3lQXJrwiaicJg9BnBw/132"> <div style="height: 16px; overflow: hidden;">直营三星</div> <div class="text-gray font-size-xs">ID:LL07647</div> <span class="mui-badge mui-badge-black font-size-xs"></span></div> 
						<div class="mui-col-xs-3 price"><span class="text-success font-size-xsm">+<span>￥20</span></span> <br><span class="text-gray">￥140.00</span></div></div>
					</div>
				
			</view>
			
			
			<view class="list_box">
				<view v-for="(item, index) in orderList" :key="index" class="lists">
					<view class="type">
						<text class="order_id">订单编号:{{item.order_sn}}</text>
						<text class="order_type" :style="'color:' + colors">
							{{item.status_info.name}}
						</text>
					</view>
					<view v-for="(row, index2) in item.goods_list" :key="index2" class="top" @tap="jumpDetails(item)">
						<image :src="row.thumb" mode="aspectFill"></image>
						<view class="top_right">
							<view class="order_name">{{row.goods_title}}</view>
							<view class="sku">规格：{{row.goods_attr || '暂无规格'}}</view>
							<view class="price">
								<view class="t1">￥{{row.goods_price}}</view>
								<view class="t3">
									x{{row.goods_number}}
								</view>
							</view>
						</view>
					</view>
					<view class="bottom">
						<view class="address"></view>
						<view class="btns">
							<text class="c-333 fz26">{{item.time_add_format}}</text>
							<block v-if="item.status_key=='unpayed'">
								<view class="pay" :style="'color:#fff;background:' + colors+ ';border-color:' + colors" @tap="jumpDetails(item)">去付款</view>
								<view class="pay shouhou" :style="'color:' + colors + ';border-color:' + colors" @tap="setAddress(item,index)">修改地址</view>	
							</block>
							<block v-if="item.status_key=='unshipped'">
								<view class="pay shouhou" :style="'color:' + colors + ';border-color:' + colors" @tap="setAddress(item,index)">修改地址</view>	
							</block>
							
							<block v-if="item.status_key=='shipped'">
								<view class="pay" :style="'color:#fff;background:' + colors+ ';border-color:' + colors">确认收货</view>
								<!-- <view class="pay shouhou" @tap="onRefund(item)">申请退款</view> -->
							</block>
							
							<view class="pay shouhou" v-if="active == 4" @click="delOrder(item)">删除订单</view>
						</view>
					</view>
				</view>
				<view class="nodata" v-if="orderList.length >= 3">—— 到底啦 ——</view>
				<nodata :colors="colors" title="暂无订单信息" v-if="orderList.length == 0"></nodata>
			</view>
		</view>
		<loading v-if="isShow == true"></loading>
	</view>
</template>

<script>
	var app = getApp();
	import tab from '../../components/tab.vue'
	import loading from "../../components/public/loading";
	import navBar from '../../components/public/navBar.vue'
	import './user.css'
	export default {
		data() {
			return {
				statusBarHeight: app.globalData.statusHeight,
				toBarHeight: app.globalData.toBar,
				tab:[
					{id:1,name:'全部'},
					{id:2,name:'待付款'},
					{id:3,name:'待收货'},
					{id:11,name:'已完成'},
					//{id:5,name:'售后'},
				],
				status:0,
				active: 0,
				orderList: [],
				isShow: true,
				colors: "#ff0000"
			};
		},
		filters: {
			setStatus(value) {
				if (value == 0) {
					return '待付款'
				} else if (value == 1) {
					return '待发货'
				} else if (value == 2) {
					return '待收货'
				} else if (value == 3) {
					return '待评价'
				} else if (value == 4) {
					return '已完成'
				}
			}
		},
		components: {
			tab,
			loading,
			navBar
		},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			if(options.status){
				this.status =  options.status
			}
			this.init();
			if (options.tabIndex) {
				this.setData({
					active: Number(options.tabIndex)
				});
			}
			this.setData({
				//colors: app.globalData.newColor
			});
			setTimeout(() => {
				this.setData({
					isShow: false
				});
			}, 600);
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {
			
		},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		created() {
		},
		methods: {
			tabClick(data) {
				this.status = data.id
				this.init();
			},
			setTabs(item, index) {
				this.setData({
					active: item.id
				});
			},

			jumpDetails(item) { //模拟跳转商品详情
			
				uni.navigateTo({
					url: '/pagePoint/order/orderDetails?order_sn=' + item.order_sn
				});
			},
			cencalOrder(item) {
				//取消订单
				uni.showModal({
					title:'确认要取消该订单吗?',
					confirmColor:this.colors,
					success: (res) => {
						if(res.confirm){
							console.log('取消成功')
						}
					}
				})
			},
			onRefund(item){
				// 申请退款
				uni.navigateTo({
					url: '/pagePoint/order/cancelOrder?orderId'
				});
			},
			setAddress(item,index) {
			  uni.navigateTo({
				url: '/pagePoint/user/myaddress?type=change&posi='+index+'&order_sn='+item.order_sn+'&item='+JSON.stringify(item)
			  });
			},
			delOrder(item){
				uni.showModal({
					title:'确认要删除该订单吗?',
					confirmColor:this.colors,
					success: (res) => {
						if(res.confirm){
							console.log('删除成功')
						}
					}
				})
			},
			async init() {
				this.isShow = true
				var query = {
					type:'order_list',
					goods_type:1,
					page:0,
					status:parseInt(this.status) - 1,
					size:20
				};
				console.log("订单列表查询条件")
				console.log(query)
				 let res = await this.$api.memberData(query).then(res=> {
					 console.log("订单列表")
						console.log(res)
						if(res.code == 0){
							this.orderList = res.data.list;
							console.log(this.orderList);
						}
						this.isShow = false;
						
				 }).catch(err=> { console.log(err) }
				 );
			}
		}
	};
</script>
<style>
	page{
		background-color: #F8F8F8;
	}
</style>
<style scoped lang="scss">
	.order_list {
		width: 100%;
		height: 100%;
		overflow: hidden;
		background-color: #FFFFFF;
	}
	.top_nav{
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 200;
	}
	.list_box {
		padding: 0 3%;
		box-sizing: border-box;
		overflow: hidden;
		/* #ifdef MP */
		padding-bottom: 50upx;
		/* #endif */
		width: 100%;
		padding-top: 20upx;
	}

	.lists {
		margin: 0 auto;
		padding: 20upx;
		margin-top: 5upx;
		background-color: #ffffff;
		border-radius: 10upx;
		margin-bottom: 20upx;
		box-shadow: 0upx 0upx 10upx #EDEDED;
		box-sizing: border-box;
		width: 98%;
	}

	.type {
		height: 50upx;
		font-size: 26upx;
		line-height: 50upx;
		font-weight: bold;
		text-align: right;
		display: flex;
		justify-content: space-between;
	}

	.type .order_id {
		font-weight: 600;
		color: #999;
		font-size: 24upx;
	}

	.lists .top {
		display: flex;
		align-content: center;
		margin-bottom: 20upx;
	}

	.lists .top image {
		min-width: 180upx;
		max-width: 180upx;
		height: 180upx;
		display: block;
		border-radius: 10upx;
	}

	.lists .top .top_right {
		margin-left: 20upx;
		width: 100%;
	}

	.lists .top .order_name {
		line-height: 80upx;
		height: 80upx;
		font-size: 26upx;
		font-weight: bold;
		color: #333;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.lists .top .sku {
		height: 40upx;
		line-height: 40upx;
		font-size: 24upx;
		border-radius: 8upx;
		padding: 0 10upx;
		color: #A7A7A7;
		background-color: #F7F7F7;
	}

	.lists .top .price {
		width: 100%;
		display: flex;
		align-items: center;
		height: 40upx;
		line-height: 40upx;
		margin-top: 20upx;
		position: relative;
	}

	.price .t1 {
		font-size: 30upx;
		// font-weight: bold;
		display: block;
		color: $mycolor;
	}

	.price .t2 {
		font-size: 24upx;
		margin-left: 15upx;
		display: block;
		color: #C5C5C5;
		text-decoration: line-through;
	}

	.price .t3 {
		float: right;
		font-weight: bold;
		font-size: 28upx;
		color: #999;
		position: absolute;
		right: 0upx;
		top: 0;
	}

	.list_box .bottom {
		margin-top: 20upx;
	}

	.list_box .bottom .address {
		font-size: 24upx;
		color: #696969;
	}

	.list_box .bottom .btns {
		margin-top: 15upx;
		overflow: hidden;
	}

	.list_box .bottom .btns .pay {
		padding: 8upx 15upx;
		border-radius: 8upx;
		text-align: center;
		font-size: 24upx;
		float: right;
		margin-left: 20upx;
		box-sizing: border-box;
		border: 1upx solid #ddd;
	}

	.pay:active {
		opacity: .8;
	}

	.nodata {
		color: #ccc;
		text-align: center;
		font-size: 24upx;
		margin-bottom: 30upx;
		height: 80upx;
		line-height: 80upx;
	}
</style>
